import {request} from '../../utils/http'

Page({
  data: {
    member: {
      id: '',
      name: '',
      mobile: '',
      token: ''
    }
  },
  onLoad(query) {
    // 页面加载
    //console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
    
  },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
    my.getStorage({
      key: 'userInfo',
      success: (res) => {
        console.log(res)
        if (res.data) {
          this.setData({
            member: res.data
          })
        }
      }
    });
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  bindKeyInputName(e) {
    let member = this.data.member;
    member.name = e.detail.value;
    this.setData({
      member
    });
  },
  bindKeyInputCertNo(e) {
    let member = this.data.member;
    member.cert_no = e.detail.value;
    this.setData({
      member
    });
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    // return {
    //   title: '微蓝辅导',
    //   desc: '微蓝辅导',
    //   path: 'pages/index/index',
    // };
  },
  
  save() {
    request('/member/update', 'post', {name: this.data.member.name, cert_no: this.data.member.cert_no}).then(res => {
      my.setStorage({
        key: 'userInfo',
        data: {
          ...this.data.member,
        },
        success: function() {
          console.log('缓存写入成功')
        }
      })
      my.showToast({content: '保存成功！'})
    })
  }
});
